asm
  ld sp,$4DFF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/pacmanputsprite.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $4C00
dim seed as uinteger at $4C02
dim ee0 as uinteger at $4C04
dim ee1 as uinteger at $4C06
dim ee2 as uinteger at $4C08
dim ee3 as uinteger at $4C0A
dim eex as uinteger at $4C0C
dim eey as uinteger at $4C0E

sub ponpokoputchar(txp1 as uinteger,typ1 as uinteger, tch1 as ubyte, tat1 as ubyte)
  poke ($4000+(txp1*32)+typ1) bxor %0000001111100000,tch1
  poke ($4400+(txp1*32)+typ1) bxor %0000001111100000,tat1
  poke $50C0,255
  end sub

sub ponpokoputcharf(txp1 as uinteger,typ1 as uinteger, tch1 as ubyte, tat1 as ubyte):
  if txp1>=2 and txp1<=33 then:
    poke ($4000+((typ1+2)*32)+(txp1-2)) bxor %0,tch1
    poke ($4400+((typ1+2)*32)+(txp1-2)) bxor %0,tat1
  else:
    poke ($4000+(( (txp1+30)band 63 )*32)+typ1+2) bxor %0,tch1
    poke ($4400+(( (txp1+30)band 63 )*32)+typ1+2) bxor %0,tat1
    end if
  poke $50C0,255
  end sub

sub ponpokoputcharer(txp1 as uinteger,typ1 as uinteger, tch1 as ubyte, tat1 as ubyte)
  poke ($4000+(typ1*32)+txp1) bxor %0000000000011111,tch1
  poke ($4400+(typ1*32)+txp1) bxor %0000000000011111,tat1
  poke $50C0,255
  end sub

seed=0


for ee2=0 to 27
  for ee3=0 to 35
    seed=smsrnd(seed)
    ee0=seed
    seed=smsrnd(seed)
    ponpokoputcharf(ee3,ee2,seed band 3,ee0 band 7)
    'pacmandelay(1000)
    next:next

for ee2=0 to 15
  for ee3=0 to 15
    ponpokoputcharf(ee3+19,ee2+11,ee2*16+ee3,0)
    'pacmandelay(1000)
    next:next


eee=0:eex=8:eey=8
do

ponpokoputcharf(1,1,48+(int(eee/100) mod 10),0)
ponpokoputcharf(2,1,48+(int(eee/10) mod 10),0)
ponpokoputcharf(3,1,48+(eee mod 10),0)

ee0=peek($5000) bxor %11100000
ponpokoputcharf(1,3,48+(int(ee0/100) mod 10),0)
ponpokoputcharf(2,3,48+(int(ee0/10) mod 10),0)
ponpokoputcharf(3,3,48+(ee0 mod 10),0)

eex=eex+((ee0 band 4)/4)-((ee0 band 2)/2)
eey=eey+((ee0 band 8)/8)-((ee0 band 1)/1)

ee0=peek($5040) bxor $00
ponpokoputcharf(1,4,48+(int(ee0/100) mod 10),0)
ponpokoputcharf(2,4,48+(int(ee0/10) mod 10),0)
ponpokoputcharf(3,4,48+(ee0 mod 10),0)

ee0=peek($5080) bxor $FF
ponpokoputcharf(1,5,48+(int(ee0/100) mod 10),0)
ponpokoputcharf(2,5,48+(int(ee0/10) mod 10),0)
ponpokoputcharf(3,5,48+(ee0 mod 10),0)

ee0=peek($50C0) bxor $FF
ponpokoputcharf(1,6,48+(int(ee0/100) mod 10),0)
ponpokoputcharf(2,6,48+(int(ee0/10) mod 10),0)
ponpokoputcharf(3,6,48+(ee0 mod 10),0)


ponpokoputcharf(eex mod 36,eey mod 28,eee mod 128,0)

eee=eee+1
loop


do:loop

'- static ADDRESS_MAP_START( woodpek_map, AS_PROGRAM, 8, pacman_state )
'- AM_RANGE(0x0000, 0x3fff) AM_ROM
'- AM_RANGE(0x4000, 0x43ff) AM_MIRROR(0xa000) AM_RAM_WRITE(pacman_videoram_w) AM_SHARE("videoram")
'- AM_RANGE(0x4400, 0x47ff) AM_MIRROR(0xa000) AM_RAM_WRITE(pacman_colorram_w) AM_SHARE("colorram")
'- AM_RANGE(0x4800, 0x4bff) AM_MIRROR(0xa000) AM_READ(pacman_read_nop) AM_WRITENOP
'- AM_RANGE(0x4c00, 0x4fef) AM_MIRROR(0xa000) AM_RAM
'- AM_RANGE(0x4ff0, 0x4fff) AM_MIRROR(0xa000) AM_RAM AM_SHARE("spriteram")
'- AM_RANGE(0x5000, 0x5000) AM_MIRROR(0xaf38) AM_WRITE(irq_mask_w)
'- AM_RANGE(0x5001, 0x5001) AM_MIRROR(0xaf38) AM_DEVWRITE("namco", namco_device, pacman_sound_enable_w)
'- AM_RANGE(0x5002, 0x5002) AM_MIRROR(0xaf38) AM_WRITENOP
'- AM_RANGE(0x5003, 0x5003) AM_MIRROR(0xaf38) AM_WRITE(pacman_flipscreen_w)
'- AM_RANGE(0x5004, 0x5005) AM_MIRROR(0xaf38) AM_WRITENOP // AM_WRITE(pacman_leds_w)
'- AM_RANGE(0x5006, 0x5006) AM_MIRROR(0xaf38) AM_WRITENOP // AM_WRITE(pacman_coin_lockout_global_w)
'- AM_RANGE(0x5007, 0x5007) AM_MIRROR(0xaf38) AM_WRITE(pacman_coin_counter_w)
'- AM_RANGE(0x5040, 0x505f) AM_MIRROR(0xaf00) AM_DEVWRITE("namco", namco_device, pacman_sound_w)
'- AM_RANGE(0x5060, 0x506f) AM_MIRROR(0xaf00) AM_WRITEONLY AM_SHARE("spriteram2")
'- AM_RANGE(0x5070, 0x507f) AM_MIRROR(0xaf00) AM_WRITENOP
'- AM_RANGE(0x5080, 0x5080) AM_MIRROR(0xaf3f) AM_WRITENOP
'- AM_RANGE(0x50c0, 0x50c0) AM_MIRROR(0xaf3f) AM_WRITE(watchdog_reset_w)
'- AM_RANGE(0x5000, 0x5000) AM_MIRROR(0xaf3f) AM_READ_PORT("IN0")
'- AM_RANGE(0x5040, 0x5040) AM_MIRROR(0xaf3f) AM_READ_PORT("IN1")
'- AM_RANGE(0x5080, 0x5080) AM_MIRROR(0xaf3f) AM_READ_PORT("DSW1")
'- AM_RANGE(0x50c0, 0x50c0) AM_MIRROR(0xaf3f) AM_READ_PORT("DSW2")
'- AM_RANGE(0x8000, 0xbfff) AM_ROM
'- ADDRESS_MAP_END




